<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" inline label-width="100px">
            <el-form-item label="分账状态：">
              <el-radio-group v-model="tableFrom.fz_status" type="button" @change="getList(1)">
                <el-radio-button label="">全部</el-radio-button>
                <el-radio-button label="-1">不支持分账</el-radio-button>
                <el-radio-button label="-2">分账失败</el-radio-button>
                <el-radio-button label="0">未分账</el-radio-button>
                <el-radio-button label="1">分账成功</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="时间选择：" class="width100">

              <el-date-picker
                v-model="timeVal"
                value-format="yyyy/MM/dd"
                format="yyyy/MM/dd"
                size="small"
                type="daterange"
                placement="bottom-end"
                placeholder="自定义时间"
                style="width: 250px;"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item label="关键字：" class="width100">
              <el-input
                v-model="tableFrom.keyword"
                placeholder="请输入付款手机号"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button slot="append" icon="el-icon-search" size="small" class="el-button-solt" @click="getList(1)"/>
              </el-input>
            </el-form-item>
            <!--            <el-form-item label="分账状态：">-->
            <!--              <el-select-->
            <!--                v-model="tableFrom.status"-->
            <!--                placeholder="请选择"-->
            <!--                class="filter-item selWidth mr20"-->
            <!--                clearable-->
            <!--                @change="getList"-->
            <!--              >-->
            <!--                <el-option-->
            <!--                  v-for="item in invoiceStatusList"-->
            <!--                  :key="item.value"-->
            <!--                  :label="item.label"-->
            <!--                  :value="item.value"-->
            <!--                />-->
            <!--              </el-select>-->
            <!--            </el-form-item>-->
            <el-form-item label="付款类型：">
              <el-radio-group v-model="tableFrom.pay_type" type="button" @change="getList(1)">
                <el-radio-button label="">全部</el-radio-button>
                <el-radio-button label="0">余额</el-radio-button>
                <el-radio-button label="1">微信</el-radio-button>
                <el-radio-button label="2">支付宝</el-radio-button>
                <el-radio-button label="3">现金券</el-radio-button>
                <el-radio-button label="4">支付宝-小程序</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="付款状态：">
              <el-radio-group v-model="tableFrom.status" type="button" @change="getList(1)">
                <el-radio-button label="">全部</el-radio-button>
                <el-radio-button label="0">未付款</el-radio-button>
                <el-radio-button label="1">已付款</el-radio-button>

              </el-radio-group>
            </el-form-item>
            <!--            <el-form-item label="订单号：" class="width100">-->
            <!--              <el-input-->
            <!--                v-model="tableFrom.username"-->
            <!--                placeholder="请输入订单号"-->
            <!--                class="selWidth"-->
            <!--                size="small"-->
            <!--                @keyup.enter.native="getList(1)"-->
            <!--              >-->
            <!--                <el-button slot="append" icon="el-icon-search" size="small" class="el-button-solt" @click="getList(1)" />-->
            <!--              </el-input>-->
            <!--            </el-form-item>-->

          </el-form>
        </div>
      </div>
      <el-table
        ref="multipleSelection"
        v-loading="listLoading"
        tooltip-effect="dark"
        :row-key="(row) => { return row.order_receipt_id }"
        :data="tableData.data"
        style="width: 100%"
        class="table"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          :reserve-selection="true"
          width="55"
        />
        <el-table-column prop="out_trade_no" label="订单号" min-width="170"/>
        <el-table-column prop="account" label="付款手机号" min-width="90"/>
        <el-table-column prop="amount" label="付款金额" min-width="90"/>
        <el-table-column label="分账金额" min-width="90" prop="share_money"></el-table-column>

        <el-table-column label="分账状态" min-width="180">
          <template slot-scope="scope">
            <span v-if="scope.row.fz_status!=-2">{{ getFZStatus(scope.row.fz_status) }}</span>
            <span v-else style="color: red"> {{ scope.row.fz_fail }}</span>
          </template>
        </el-table-column>
        <el-table-column label="分账状态" min-width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.status == 0 ? '未付款' : '已付款' }}</span>
            <!--            <span v-else> {{scope.row.fz_fail}}</span>-->
          </template>
        </el-table-column>
        <el-table-column label="付款类型" min-width="120">
          <template slot-scope="scope">
            <span>{{ getPayType(scope.row.pay_type) }}</span>
            <!--            <span v-else>&#45;&#45;</span>-->
          </template>
        </el-table-column>
        <el-table-column label="分账时间" min-width="100" prop="create_time">

        </el-table-column>
        <!--        <el-table-column label="操作" min-width="180" fixed="right" align="center">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-button v-if="scope.row.status === 0 && scope.row.storeOrder && scope.row.storeOrder.paid === 1" type="text" size="small" @click="getInvoiceInfo(scope.row.order_receipt_id,'invoice')">开票</el-button>-->
        <!--            <el-button type="text" size="small" @click="onOrderDetail(scope.row.order_id)">订单详情</el-button>-->
        <!--            <el-button v-if="scope.row.status" type="text" size="small" @click="getInvoiceInfo(scope.row.order_receipt_id,'edit')">编辑</el-button>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>

import { merSelectApi } from '@/api/product'
import {
  transferDetailApi,
  transferReviewApi,
  transferEditApi,
  transferMarkApi,
  transferHeaderDataApi,
  transferRecordsExportApi,
  billList
} from '@/api/accounts'
import cardsData from '@/components/cards/index'
import fileList from '@/components/exportFile/fileList'

export default {
  components: { cardsData, fileList },
  name: 'offLineWater',
  data() {
    return {
      type: '',
      tableData: {
        data: [],
        total: 0
      },
      invoiceStatusList: [
        { label: '全部', value: null },
        { label: '不支持分账', value: '-1' },
        { label: '已分账失败开票', value: '-2' },
        { label: '未分账', value: '0' },
        { label: '分账成功', value: '1' }

      ],

      tableFrom: {
        pay_type: null,//支付类型 0，1，,2，,3，,4 ye'，'wx'，'zf''zf'rq',
        fz_status: null,//:-2,-1,0,1'
        date: null,
        page: 1,
        limit: 20,
        keyword: null,
        status: null//|支付状态 0 ,1
      },
      arrivalStatusList: [
        { label: '已到账', value: 1 },
        { label: '未到账', value: 0 }
      ],
      listLoading: true,
      cardLists: [],
      voucher_image: [],
      formValidate: {
        status: 1,
        refusal: ''
      },
      approvalStatus: 0,

      orderChartType: {},
      timeVal: [],
      fromList: {
        title: '选择时间',
        custom: true,
        fromTxt: [
          { text: '全部', val: '' },
          { text: '今天', val: 'today' },
          { text: '昨天', val: 'yesterday' },
          { text: '最近7天', val: 'lately7' },
          { text: '最近30天', val: 'lately30' },
          { text: '本月', val: 'month' },
          { text: '本年', val: 'year' }
        ]
      },
      merSelect: [],
      tableFromLog: {
        page: 1,
        limit: 20
      },
      tableDataLog: {
        data: [],
        total: 0
      },
      loading: false,
      dialogVisible: false,
      pictureVisible: false,
      pictureUrl: '',
      transferData: {
        financial_account: {}
      }
    }
  },
  mounted() {
    this.getList(1)
    this.getMerSelect()
    this.getHeaderData()
  },

  methods: {
    // 商户列表；
    getMerSelect() {
      merSelectApi()
        .then((res) => {
          this.merSelect = res.data
        })
        .catch((res) => {
          this.$message.error(res.message)
        })
    },
    // 头部数据
    getHeaderData() {
      transferHeaderDataApi().then((res) => {
        this.cardLists = res.data
      })
        .catch((res) => {
          this.$message.error(res.message)
        })
    },
    // 转账信息
    transferDetail(id, num) {
      if (num) this.voucher_image = []
      transferDetailApi(id).then(res => {
        this.listLoading = false
        this.dialogVisible = true
        this.transferData = res.data
        this.formValidate.status = res.data.status
        if (num) {
          this.voucher_image = []
        } else {
          this.voucher_image = res.data.image
        }
      })
        .catch(res => {
          this.listLoading = false
          this.$message.error(res.message)
        })
    },
    //获取支付二维码
    getPicture(url) {
      this.pictureVisible = true
      this.pictureUrl = url
    },
    // 审核
    transferReview(id) {
      let parmas = {
        status: this.formValidate.status,
        refusal: this.formValidate.refusal
      }
      transferReviewApi(id, parmas).then(res => {
        this.listLoading = false
        this.$message.success(res.message)
        this.dialogVisible = false
        this.getList(1)
      }).catch(res => {
        this.listLoading = false
        this.$message.error(res.message)
      })

    },
    // 备注
    transferMark(id) {
      this.$modalForm(transferMarkApi(id)).then(() => this.getList('1'))
    },
    // 转账提交
    onSubmit(id) {
      if (this.voucher_image == 0) {
        return this.$message.error('请上传转账凭证！')
      } else {
        transferEditApi(id, { image: this.voucher_image }).then(res => {
          this.$message.success(res.message)
          this.dialogVisible = false
          this.getList(1)
        }).catch(res => {
          this.$message.error(res.message)
        })
      }

    },
    // 点击商品图
    modalPicTap(tit, num, i) {
      const _this = this
      const attr = []
      this.$modalUpload(function(img) {
        if (tit === '2' && !num) {
          img.map((item) => {
            attr.push(item.attachment_src)
            _this.voucher_image.push(item)
            if (_this.voucher_image.length > 6) {
              _this.voucher_image.length = 6
            }
          })
        }
      }, tit)
    },
    handleRemove(i) {
      this.voucher_image.splice(i, 1)
    },
    getFZStatus(status) {
      switch (status) {
        case 0 :
          return '未分账'
          break
        case 1 :
          return '分账成功'
          break
        case -1 :
          return '不支持分账'
          break
        case -2 :
          return '分账失败'
          break

      }
    },
    getPayType(type) {
      switch (type) {
        case 0 :
          return '余额支付'
          break
        case 1 :
          return '微信支付'
          break
        case 2 :
          return '支付宝支付'
          break
        case 3 :
          return '现金券支付'
          break
        case 4:
          return '支付宝小程序支付'
          break

      }
    },
    // 选择时间
    selectChange(tab) {
      this.tableFrom.date = tab
      this.timeVal = []
      this.getList(1)
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e
      this.tableFrom.date = e ? this.timeVal.join('-') : ''
      this.getList(1)
    },
    // 导出
    exportRecord() {
      transferRecordsExportApi(this.tableFrom)
        .then((res) => {
          /*this.$message.success(res.message)
          this.$refs.exportList.exportFileList()*/
          const h = this.$createElement
          this.$msgbox({
            title: '提示',
            message: h('p', null, [
              h('span', null, '文件正在生成中，请稍后点击"'),
              h('span', { style: 'color: teal' }, '导出记录'),
              h('span', null, '"查看~ ')
            ]),
            confirmButtonText: '我知道了'
          }).then(action => {

          })
        })
        .catch((res) => {
          this.$message.error(res.message)
        })
    },
    // 导出列表
    getExportFileList() {
      this.$refs.exportList.exportFileList()
    },
    // 列表
    getList(num) {
      this.listLoading = true
      this.tableFrom.page = num ? num : this.tableFrom.page
      billList(this.tableFrom)
        .then(res => {
          this.tableData.data = res.data.list
          this.tableData.total = res.data.count
          this.listLoading = false
        })
        .catch(res => {
          this.$message.error(res.message)
          this.listLoading = false
        })
    },
    pageChange(page) {
      this.tableFrom.page = page
      this.getList()
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val
      this.getList()
    },

    handleClose() {
      this.dialogLogistics = false
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-dialog__title {
  font-weight: bold;
}

.selWidth {
  width: 300px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}

.pictrue {
  width: 60px;
  height: 60px;
  border: 1px dotted rgba(0, 0, 0, 0.1);
  margin-right: 10px;
  position: relative;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}

.btndel {
  position: absolute;
  z-index: 1;
  width: 20px !important;
  height: 20px !important;
  left: 46px;
  top: -4px;
}

.box-container {
  overflow: hidden;
  padding: 0 10px;
}

.box-container .title {
  margin: 15px 0 10px;
  color: #333;
  font-weight: bold;
  border-bottom: 1px solid #dfe6ec;
}

.box-container .list {
  float: left;
  line-height: 40px;
}

.box-container .list .info {
  display: block;

  .el-textarea {
    margin-top: 10px;
  }
}

.box-container .list.image {
  margin: 20px 0;
  position: relative;
}

.box-container .list.image img {
  position: absolute;
  top: -20px;
}

.box-container .sp {
  width: 50%;
}

.box-container .sp3 {
  width: 33.3333%;
}

.box-container .sp100 {
  width: 100%;
}

.box-container .list .name {
  align-items: center;
  display: inline-block;
  //   width: 130px;
  color: #606266;
  text-align: right;
}

.acea-row {
  margin-bottom: 25px;
}

.pictures {
  width: 100%;
  max-width: 100%;
}
</style>
